package com.hh.vietnameseproject.ui.changeplan

import android.app.Activity
import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.hh.vietnameseproject.R
import com.hh.vietnameseproject.databinding.ActivityChangePlanBinding
import com.hh.vietnameseproject.logic.model.WordList
import com.hh.vietnameseproject.ui.login.ActivityController

class ChangePlanActivity : AppCompatActivity() {
    lateinit var binding: ActivityChangePlanBinding
    lateinit var adapter: PlanRecyclerViewAdapter
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityChangePlanBinding.inflate(layoutInflater)
        setContentView(binding.root)
        ActivityController.addList(this)
        val list = intent.getParcelableArrayListExtra<WordList>("list")

        adapter = PlanRecyclerViewAdapter(
            this, list!!
        )
        val layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
        binding.changePlanRecycler.layoutManager = layoutManager
        binding.changePlanRecycler.adapter = adapter
        binding.changePlanRecycler.setHasFixedSize(true)

        binding.changePlanBackImage.setOnClickListener {
            finish()
        }


    }
    companion object{
        fun actionStart(context: Context?,list:ArrayList<WordList>){
            val intent = Intent(context,ChangePlanActivity::class.java)
            intent.putExtra("list",list)
            context?.startActivity(intent)
        }


    }

    override fun onDestroy() {
        super.onDestroy()
        ActivityController.removeList(this)
    }
}